package org.dromara.erp.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.erp.domain.ErpCostOutInfo;
import org.dromara.erp.service.IErpCostOutInfoService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 支出明细
 *
 * @author Mr Lei QQ:235921049
 * @date 2024-06-22
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/erp/erpCostOutInfo")
public class ErpCostOutInfoController extends BaseController {

    private final IErpCostOutInfoService erpCostOutInfoService;

    /**
     * 查询支出明细列表
     */
    @SaCheckPermission("erp:erpCostOutInfo:list")
    @GetMapping("/list")
    public TableDataInfo<ErpCostOutInfo> list(ErpCostOutInfo bo, PageQuery pageQuery) {
        return erpCostOutInfoService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出支出明细列表
     */
    @SaCheckPermission("erp:erpCostOutInfo:export")
    @Log(title = "支出明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ErpCostOutInfo bo, HttpServletResponse response) {
        List<ErpCostOutInfo> list = erpCostOutInfoService.queryList(bo);
        ExcelUtil.exportExcel(list, "支出明细", ErpCostOutInfo.class, response);
    }

    /**
     * 获取支出明细详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("erp:erpCostOutInfo:query")
    @GetMapping("/{id}")
    public R<ErpCostOutInfo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(erpCostOutInfoService.queryById(id));
    }

    /**
     * 新增支出明细
     */
    @SaCheckPermission("erp:erpCostOutInfo:add")
    @Log(title = "支出明细", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ErpCostOutInfo bo) {
        return toAjax(erpCostOutInfoService.insertByBo(bo));
    }

    /**
     * 修改支出明细
     */
    @SaCheckPermission("erp:erpCostOutInfo:edit")
    @Log(title = "支出明细", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ErpCostOutInfo bo) {
        return toAjax(erpCostOutInfoService.updateByBo(bo));
    }

    /**
     * 删除支出明细
     *
     * @param ids 主键串
     */
    @SaCheckPermission("erp:erpCostOutInfo:remove")
    @Log(title = "支出明细", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(erpCostOutInfoService.deleteWithValidByIds(List.of(ids), true));
    }
}
